import { ipcMain } from 'electron'
import { send as sendMainWindow } from './windows/main'
import { create as createControlWindow } from './windows/control'

export default function () {
  ipcMain.handle('login', async () => {
    // mock 返回控制码
    const code = Math.floor(Math.random() * (999999 - 100000)) + 100000

    return code
  })

  ipcMain.on('control', async (e, remoteCode) => {
    // 这里跟服务端交互 但是先mock返回
    sendMainWindow('control-state-change', remoteCode, 1)
    createControlWindow()
  })
}
